<template>
  <div class="doc_wrap">
    <el-divider content-position="left">会诊方信息</el-divider>
    <!-- <div class="doc_tit">会诊方</div> -->
    <div class="doc_list" :class="labelBox?'':'doc_lab_txt'">
      <div class="doc_list_col" v-if="isConsultantTeam">
        <div class="doc_btns" v-if="source=='fz' || source==''">
          <!-- <el-button type="primary" plain size="mini" @click="setzz">主责</el-button> -->
          <el-button type="danger" plain size="mini" @click="teamDel">删除</el-button>
        </div>
        <div class="doc_list_item" v-if="consultantTeam.TeamName">
          <div class="doc_lab">会诊团队：</div>
          <div class="doc_txt">{{consultantTeam.TeamName}}</div>
        </div>
        <div class="doc_list_item" v-if="consultantTeam.HospitalName">
          <div class="doc_lab">会诊医院：</div>
          <div class="doc_txt">{{consultantTeam.HospitalName}}</div>
        </div>
        <div class="doc_list_item" v-if="consultantTeam.DepName">
          <div class="doc_lab">会诊科室：</div>
          <div class="doc_txt">{{consultantTeam.DepName}}</div>
        </div>
      </div>
      <template v-if="consultantDoctor.length>0">
        <div
          class="doc_list_col"
          v-for="(item) in consultantDoctor"
          :key="item.id"
          :class="item.responsible==1?'doc_list_bg':''"
        >
          <div class="doc_btns" v-if="source=='fz' || source==''">
            <el-button
              v-if="item.responsible!=1"
              type="primary"
              plain
              size="mini"
              @click="setzz(item.id)"
            >主责</el-button>
            <el-button type="danger" plain size="mini" @click="doctorDel(item.id)">删除</el-button>
          </div>
          <div class="doc_list_item">
            <div class="doc_lab">会诊医生：</div>
            <div class="doc_txt">
              {{item.userName}}
              <span v-if="item.responsible==1" style="color:red;">主责</span>
            </div>
          </div>
          <div class="doc_list_item">
            <div class="doc_lab">会诊专长：</div>
            <div class="doc_txt">{{item.expertSpeciality | isNone}}</div>
          </div>
          <div class="doc_list_item">
            <div class="doc_lab">会诊科室：</div>
            <div class="doc_txt">{{item.department}}</div>
          </div>
          <div class="doc_list_item">
            <div class="doc_lab">会诊医院：</div>
            <div class="doc_txt">{{item.hospital}}</div>
          </div>
        </div>
      </template>
    </div>
  </div>
</template>

<script>
import {
  // getRemoteExpertDiagnosisList,
  getUpdateResponsible,
  deleteRemoteExpertDiagnosis

  // getApplyExpertList
} from 'api/api.js'
import bus from '@/api/bus'
import store from '@/store'
export default {
  props: {
    source: {
      // 申请单阶段
      type: String,
      default: ''
    },
    consultantTeam: {
      // 会诊方团队/医院/科室信息
      type: Object,
      default: null
    },
    applyId: {
      type: String,
      default: ''
    },
    labelBox: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      isConsultantTeam: false,
      consultantDoctor: [] // 会诊方医生列表
    }
  },
  filters: {
    isNone(val) {
      return val || '-'
    }
  },
  watch: {
    consultantTeam() {
      this.consultantTeamFilter()
    }
  },
  created() {
    // this.getDoctorList();
  },
  methods: {
    // 获取会诊方医生列表
    // getDoctorList(applyid) {
    //   const that = this;
    //   const _applyid = applyid ? applyid : that.applyId
    //   if (_applyid) {
    //     // getRemoteExpertDiagnosisList
    //     getApplyExpertList({ applyId: _applyid }).then(res => {
    //       if (res && res.code == 10000) {
    //         that.consultantDoctor = res.content.list;
    //         that.setZZYTH()
    //         bus.$emit('consultantDoctorChange', that.consultantDoctor); //触发事件
    //       }
    //     });
    //   }
    // },
    // 设置全局医生主责判断
    setZZYTH() {
      store.dispatch('user/resetIszz', false)
      let zzId = ''
      this.consultantDoctor.forEach(item => {
        if (item.responsible == 1) {
          zzId = item.expertId
        }
      })
      if (zzId == this.$store.state.user.id) {
        store.dispatch('user/resetIszz', true)
      }
    },
    // 删除医生
    doctorDel(id) {
      const that = this
      if (id) {
        deleteRemoteExpertDiagnosis({ id: id }).then(res => {
          if (res && res.code == 10000) {
            // that.getDoctorList();
            that.consultantDoctor.splice(
              that.consultantDoctor.findIndex(item => item.id === id),
              1
            )
            bus.$emit('consultantDoctorChange', that.consultantDoctor) // 触发事件
          }
        })
      }
    },
    // 设置主责
    setzz(id) {
      const that = this
      if (id) {
        getUpdateResponsible({ id: id }).then(res => {
          if (res && res.code == 10000) {
            // that.getDoctorList();
            that.consultantDoctor.forEach(item => {
              if (item.id == id) {
                item.responsible = '1'
              } else {
                item.responsible = '0'
              }
            })
            bus.$emit('consultantDoctorChange', that.consultantDoctor) // 触发事件
          }
        })
      }
    },
    teamDel() {
      this.$emit('teamDel')
    },
    consultantTeamFilter() {
      const that = this
      that.isConsultantTeam = false
      Object.keys(that.consultantTeam).forEach(key => {
        if (
          that.consultantTeam[key] != null &&
          that.consultantTeam[key] != ''
        ) {
          that.isConsultantTeam = true
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.doc_list_col {
  overflow: hidden;
  padding: 2px 0 2px 0;
  border-bottom: solid 1px #f9f9f9;
  padding-right: 200px;
  position: relative;
  .doc_list_item {
    width: 25%;
    min-width: 300px;
    float: left;
    margin: 2px 0;
    line-height: 30px;
    .doc_lab {
      float: left;
      padding-left: 10px;
      background-color: #e5e9f2;
      border-radius: 3px;
    }
    .doc_txt {
      margin-left: 100px;
      line-height: 1.4em;
      margin-top: 6px;
    }
  }
  .doc_btns {
    position: absolute;
    width: 200px;
    right: 0;
    top: 5px;
    text-align: right;
  }
}
.doc_lab_txt {
  .doc_list_item {
    .doc_lab {
      width: 100px;
      text-align: right;
      font-weight: bold;
      background: none;
    }
  }
}
.doc_list_col:last-child {
  border: none;
}
.doc_list_bg {
  background: rgba(236, 245, 255, 0.3);
}
</style>
